    //DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;

namespace STT.Business
{
    public class BTbNhomNL
    {
        public static DataTable Search(ETbNhomNL dt)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenNhomNL", dt.TenNhomNL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbNhomNL_Search", pr);
            return all;
        }
        //-----------------------------------------------------------//
        public static bool KiemTraDuLieu_Sua(ETbNhomNL dt)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenNhomNL", dt.TenNhomNL);
            pr[1] = new SqlParameter(@"MaNhomNL", dt.MaNhomNL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbNhomNL_KiemTraDuLieu_Sua", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//
        public static bool KiemTraDuLieu(ETbNhomNL dt)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenNhomNL", dt.TenNhomNL);
     
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbNhomNL_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbNhomNL_SelectAll", null);
            return all;
        }
        //-----------------------------------------------------------//
        public static DataTable SelectAll1()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbNhomNL_SelectAll1", null);
            return all;
        }
        //-----------------------------------------------------------//
        public static void Insert(ETbNhomNL OTbNhomNL)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenNhomNL", OTbNhomNL.TenNhomNL);
           
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbNhomNL_Insert", pr);
        }
        //-----------------------------------------------------------//
        public static void Update(ETbNhomNL OTbNhomNL)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaNhomNL", OTbNhomNL.MaNhomNL);
            pr[1] = new SqlParameter(@"TenNhomNL", OTbNhomNL.TenNhomNL);
       
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbNhomNL_Update", pr);
        }
        //-----------------------------------------------------------//
        public static void Delete(int MaNhomNL)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaNhomNL", MaNhomNL);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbNhomNL_Delete", pr);
        }
        //-----------------------------------------------------------//
        public static ETbNhomNL SelectByID(int MaNhomNL)
        {
            ETbNhomNL OTbNhomNL = new ETbNhomNL();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaNhomNL", MaNhomNL);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbNhomNL_SelectByID", pr);
            if (idr.Read())
                OTbNhomNL = GetOneTbNhomNL(idr);
            idr.Close();
            idr.Dispose();
            return OTbNhomNL;
        }
        //-----------------------------------------------------------//
        private static ETbNhomNL GetOneTbNhomNL(IDataReader idr)
        {
            ETbNhomNL OTbNhomNL = new ETbNhomNL();
            if (idr["MaNhomNL"] != DBNull.Value)
                OTbNhomNL.MaNhomNL = (int)idr["MaNhomNL"];
            if (idr["TenNhomNL"] != DBNull.Value)
                OTbNhomNL.TenNhomNL = (string)idr["TenNhomNL"];
          
            return OTbNhomNL;
        }
        //-----------------------------------------------------------//
        public static bool TestByID(int MaNhomNL)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaNhomNL", MaNhomNL);
            pr[1] = new SqlParameter(@"TestID", SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbNhomNL_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
        //-----------------------------------------------------------//
        public static List<ETbNhomNL> ListAll()
        {
            List<ETbNhomNL> list = new List<ETbNhomNL>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbNhomNL_SelectAll", null);
            while (idr.Read())
                list.Add(GetOneTbNhomNL(idr));
            if (idr.IsClosed == false)
            {
                idr.Close();
                idr.Dispose();
            }
            return list;
        }
    }

}
